class Point {
    x: number;
    y: number;

    constructor(x: number, y: number) {
        this.x = x;
        this.y = y;
    }

    set(x: number, y: number) {
        this.x = x;
        this.y = y;

        return this;
    }

    add(point: Point) {
        this.x += point.x;
        this.y += point.y;

        return this;
    }

    subtract(point: Point) {
        this.x -= point.x;
        this.y -= point.y;

        return this;
    }

    divide(num: number) {
        this.x /= num;
        this.y /= num;

        return this;
    }

    equal(point: Point) {
        return this.x === point.x && this.y === point.y;
    }

    clone() {
        return new Point(this.x, this.y);
    }

    distanceTo(point: Point) {
        return Math.sqrt((this.x - point.x) ** 2 + (this.y - point.y) ** 2);
    }

    rotate(angle: number) {
        const cos = Math.cos(angle);
        const sin = Math.sin(angle);

        const x = cos * this.x - sin * this.y;
        const y = sin * this.x + cos * this.y;

        this.x = x;
        this.y = y;
        return this;
    }

    multiply(num: number) {
        this.x *= num;
        this.y *= num;
        return this;
    }

    getLength() {
        return Math.sqrt(this.x ** 2 + this.y ** 2);
    }

    floor() {
        this.x = Math.floor(this.x);
        this.y = Math.floor(this.y);
        return this;
    }

    ceil() {
        this.x = Math.ceil(this.x);
        this.y = Math.ceil(this.y);
        return this;
    }

    round() {
        this.x = Math.round(this.x);
        this.y = Math.round(this.y);
        return this;
    }
}

export default Point;
